// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#ifndef WINVER                          // Specifies that the minimum required platform is Windows Vista.
#define WINVER 0x0600           // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINDOWS          // Specifies that the minimum required platform is Windows 98.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif

#ifndef _WIN32_IE                       // Specifies that the minimum required platform is Internet Explorer 7.0.
#define _WIN32_IE 0x0700        // Change this to the appropriate value to target other versions of IE.
#endif

#define NOMINMAX

// Windows Header Files:
#include <windows.h>

// C RunTime Header Files
#include <stdlib.h>
#include <time.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <crtdbg.h>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#include <d3d10_1.h>
#include <d3dx10.h>

//voor timegettime
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")

//voor DXTrace
#pragma comment(lib, "dxerr9.lib")
#include "dxerr9.h"

using namespace std;

#ifdef _UNICODE	// extra unicode defines
	#define tstring wstring
	#define tcin wcin
	#define tcout wcout
	#define tstringstream wstringstream
	#define tofstream wofstream
	#define tifstream wifstream
	#define tfstream wfstream
	#define tof _wtof
#else
	#define tstring string
	#define tcin cin
	#define tcout cout
	#define tstringstream stringstream
	#define tofstream ofstream
	#define tifstream ifstream
	#define tfstream fstream
	#define tof atof
#endif

#if defined(DEBUG) | defined(_DEBUG)
	#ifndef HR
	#define HR(x)                                      \
	{                                                  \
		HRESULT hr = x;                                \
		if(FAILED(hr))                                 \
		{                                              \
			DXTrace(__FILE__, __LINE__, hr, _T(#x), TRUE); \
		}                                              \
	}
	#endif

#else
	#ifndef HR
	#define HR(x) x;
	#endif
#endif 

const float INFINITY = FLT_MAX;

struct AABB 
{
	// Initialize to an infinitely small bounding box.
	AABB()
		: minPt(INFINITY, INFINITY, INFINITY),
		maxPt(-INFINITY, -INFINITY, -INFINITY){}

	D3DXVECTOR3 center()
	{
		return 0.5f*(minPt+maxPt);
	}
	D3DXVECTOR3 size()
	{
		return D3DXVECTOR3(maxPt.x-minPt.x,maxPt.y-minPt.y,maxPt.z-minPt.z);
	}
	D3DXVECTOR3 minPt;
	D3DXVECTOR3 maxPt;
};

inline int Random(int imin, int imax)
{
	int range=(imax-imin)+1;
	return imin+int(range*rand()/(RAND_MAX + 1.0)); 
}

inline int MakeInt(tstring& tekst)
{
	// Verwijder de punt in 1000 tallen
	UINT pos = tekst.find(_T("."));
	if(pos != string::npos)
	{
		tstring temp = tekst.substr(0, pos);
		temp += tekst.substr(pos+1);
		tekst = temp;
	}

	tstringstream buffer;
	int out;
	buffer << tekst;
	buffer >> out;
	return out;
}
inline float MakeFloat(tstring& text)
{
	// Change , to .
	UINT pos = text.find(_T(","));
	if(pos != string::npos)
	{
		tstring temp = text.substr(0, pos);
		temp += _T(".");
		temp += text.substr(pos+1);
		text = temp;
	}

	tstringstream buffer;
	float out;
	buffer << text;
	buffer >> out;
	return out;
}
inline bool MakeBool(const tstring& text)
{
	if(text == _T("1"))
		return true;
	else
		return false;
}
